package com.twu.biblioteca.command;

import com.twu.biblioteca.BibliotecaApp;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by jjwang on 4/19/14.
 */
public class Checkout implements Command {
    String name = "Checkout";

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String doExecute(BibliotecaApp app) {
        if(app.getCurrentUser() == null){
            return "Please login first!\n";
        }

        System.out.println("Book or Movie?");
        String type = app.input();
        String b[] = {"Book","Movie"};
        List<String> a;
        a = new ArrayList<String>();
        Collections.addAll(a, b);
        boolean success = false;

        if(!a.contains(type))
        {
           return "Invalid type!\n";
        }
        System.out.println("Which "+type+" do you want checkout?");
        String name = app.input();

        if(type.equals("Book")){
            success = app.getLibrary().checkoutBook(name,app.getCurrentUser());
        }else if(type.equals("Movie")){
            success = app.getLibrary().checkoutMovie(name,app.getCurrentUser());
        }

        if (success) {
            return "Thank you! Enjoy the "+type+"!\n";
        }else {
            return "That "+type+" is not available.\n";
        }
    }
}
